//
//  SSDKDataHelper.m
//  SuperSDK
//
//  Created by wyht－ios－dev on 15/10/7.
//  Copyright © 2015年 WYHT. All rights reserved.
//

#import "SSDKDataHelper.h"
#import "SSDKDataKeys.h"

@implementation SSDKDataHelper

#pragma mark Singleton Method

static SSDKDataHelper *instance = nil;

+ (id) instance
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
        instance.data = [[NSMutableDictionary alloc] init];
        instance.sdkConfig = [[NSMutableDictionary alloc] init];
        instance.remoteSDKConfigEnable = NO;
    });
    return instance;
}

+ (void) setLoginAppData:(NSString *)loginAppData {
    [self setDataValue:loginAppData forKey:LOGIN_APP_DATA];
}

+ (NSString *) loginAppData {
    return (NSString *) [self dataValueWithKey:LOGIN_APP_DATA];
}

+ (void) setDataValue:(NSObject *)value
               forKey:(NSString *)key {
    if (!instance) {
        [self instance];
    }
    
    [instance.data setValue:value forKey:key];
}

+ (NSObject *) dataValueWithKey:(NSString *)key {
    if (!instance) {
        [self instance];
    }
    
    return [instance.data valueForKey:key];
}

+ (void) setSdkConfig:(NSMutableDictionary *)config {
    if (!instance) {
        [self instance];
    }
    instance.sdkConfig = config;
}

+ (NSMutableDictionary *) sdkConfig {
    if (!instance) {
        [self instance];
    }
    return instance.sdkConfig;
}

+ (void) setRemoteSDKConfigEnable:(BOOL)enable {
    if (!instance) {
        [self instance];
    }
    
    instance.remoteSDKConfigEnable = enable;
}

+ (BOOL) remoteSDKConfigEnable {
    if (!instance) {
        return false;
    }
    
    return instance.remoteSDKConfigEnable;
}

+ (void) removeDataByKey : (NSString *) key {
    if (!instance) {
        [self instance];
    }
    [instance.data removeObjectForKey:key];
}

@end
